<template>
    <div class="up_door">
        <div class="cartTable">
            <el-table border v-loading="loading_Door" :data="UpDoorData" style="width: 100%">
                <el-table-column prop="serialId" label="单号" width="190" />
                <el-table-column prop="depName" label="部门" width="130" />
                <el-table-column prop="dname" label="工作人员" width="130" />
                <el-table-column prop="sstate" label="状态" width="130">
                    <template #default="scope">
                        <span v-if="scope.row.sstate==0">进行中</span>
                        <span v-else-if="scope.row.sstate==1">完成</span>
                        <span v-else-if="scope.row.sstate==2">异常</span>
                    </template>
                </el-table-column>
                <el-table-column prop="startTime" label="开始时间" width="160" />
                <el-table-column prop="endTime" label="结束时间" width="160" />
                <el-table-column prop="address" label="地址" width="200" />
                <el-table-column prop="price" label="价格" width="100"/>
                <el-table-column prop="descrs" label="备注" width="220" />
                <el-table-column prop="createTime" label="创建时间" width="190" />
                <el-table-column fixed="right" label="操作" width="220">
                    <template #default="scope">
                        <el-button type="danger" size="small" @click="updateDoor(scope.row)">拒绝上门</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>
<script>
import { defineComponent } from '@vue/composition-api'
import { getCurrentInstance} from 'vue'
import { ElMessage  } from 'element-plus'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex' 
export default defineComponent({
    setup() {
        // 路由
        const route = useRouter();
        // vuex的数据对象
        const store = useStore();
        const { proxy } = getCurrentInstance();
        return{
            proxy,
            route,
            store
        } 
    },
    data(){
        return{
            UpDoorData:[],
            loading_Door:false,
            user:null
        }
    },
    created () {
        this.user = this.store.state.UserMessage;
        this.loadUpDoorData();
    },
    methods:{
        loadUpDoorData(){
            let self = this;
            let row = {
                did:this.user.Id,
                serviceId:2
            }
            self.$http.post(`${self.baseUrl}/business/ConditionQuery`,row).then(res=>{
                self.UpDoorData = res.data;
            })
        },
        updateDoor(msg){
            let self = this;
            console.log(msg);
            let row = {
                did:msg.did,
                id:msg.id
            };
            self.$http.post(`${self.baseUrl}/business/updateDid`,row).then(res=>{
                if(res.data!=0){
                    ElMessage({
                        message:"更换成功",
                        type:'success'
                    })
                    self.loadUpDoorData();
                }else{
                    ElMessage({
                        message:"更换失败",
                        type:'error'
                    })
                }
            })
        },
        initial(){
            return{
                "id":1,
                "userName":"",
                "userPass":"",
                "Identify":"-1",
                "umail":"",
                "createTime":""
            }
        }
    }
})
</script>
<style scoped>

</style>